#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys

INPUT_FILE = 'tracking.txt'
INPUT = os.path.join('.', INPUT_FILE)

OUTPUT_FILE = 'salida.txt'
OUTPUT = os.path.join('.', OUTPUT_FILE)

f1 = open(INPUT_FILE, 'r+')
f2 = open(OUTPUT_FILE, 'w+')

frames = {}

for l in f1.readlines():

    aux = l.split(';')
    frame = aux[0]
    obj = aux[1]
    x, y = aux[2], aux[3]
    w, h = aux[4], aux[5]
    hs, vs = aux[6], aux[7]
    mov = aux[8]

    line = (':' + obj + ';' + x + ';' + y + ';'  + w + ';' + h + ';')
    line += (hs + ';' + vs + ';' + mov)

    if frames.has_key(int(frame)):
        frames[int(frame)] = (frames[int(frame)].rstrip() + line)
    else:
        frames[int(frame)] = (frame + line)

my_list = frames.keys()
my_list.sort()

for k in my_list:
    f2.write(frames[k])

f1.close()
f2.close()
